package com.sanyang.lawyer.controller.adm;

import com.sanyang.lawyer.entity.Adm_Notice;
import com.sanyang.lawyer.service.adm.AdmNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sanyang.lawyer.entity.Adm_Notice;
import com.sanyang.lawyer.entity.Log_Table;
import com.sanyang.lawyer.entity.System_user;
import com.sanyang.lawyer.service.adm.AdmNoticeService;
import com.sanyang.lawyer.service.system.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: lawyer
 * @description: 行政Controller层
 * @author: Mr.Wang
 * @create: 2019-10-21 15:56
 **/

@RestController
@RequestMapping("adm")
public class AdmController {

    @Autowired
    private AdmNoticeService admNoticeService;

    @Autowired
    private UserService userService;

    @RequestMapping("listall")
    public List<Adm_Notice> listall(int id){
        List<Adm_Notice> list=admNoticeService.listall(id);
        return list;
    }

    @RequestMapping("listallcelc")
    public List<Adm_Notice> listallcelc(){
        List<Adm_Notice> list=admNoticeService.listallcelc();
        return list;
    }

    @RequestMapping("rense")
    public String rense(int uid){
        System_user systemUser=userService.getById(uid);
        return systemUser.getUserName();
    }

    @RequestMapping("fuzzyquery")
    public List<Adm_Notice> fuzzyquery(String title,String jdate,String kdate,String id){
        Map<String,String> map=new HashMap<String,String>();
        if(id!=null&&id!=""){
            map.put("id",id);
        }
        if(title!=""&&title!=null){
            map.put("title",title);
        }
        if(jdate!=""&&jdate!=null){
            map.put("jdate",jdate);
        }
        if(kdate!=""&&kdate!=null){
            map.put("kdate",kdate);
        }
        List<Adm_Notice> list=admNoticeService.fuzzyquery(map);
        return list;
    }

    @RequestMapping("queryinfo")
    public Adm_Notice queryinfo(int id){
        Adm_Notice admNotice=admNoticeService.getbyid(id);
        return admNotice;
    }

    @RequestMapping("deletenotice")
    public String deletenotice(int noticeId){
        admNoticeService.deletenotice(noticeId);
        return "1";
    }

    @RequestMapping("upd")
    public Adm_Notice upd(int id){      //修改获取显示
        Adm_Notice admNotice=admNoticeService.getbyid(id);
        return admNotice;
    }
    @RequestMapping("update")
    public String update(@RequestParam("data")String data) throws Exception {
        Adm_Notice adm=new Adm_Notice();
        ObjectMapper objectMapper = new ObjectMapper();
        Adm_Notice admNotice=objectMapper.readValue(data,adm.getClass());
        admNoticeService.update(admNotice);
        return "1";
    }

    @RequestMapping("insert")
    public String insert(@RequestParam("data")String data) throws IOException {
        Adm_Notice adm=new Adm_Notice();
        ObjectMapper objectMapper = new ObjectMapper();
        Adm_Notice admNotice=objectMapper.readValue(data,adm.getClass());
        admNoticeService.insert(admNotice);
        return "1";
    }
}
